# 导包
import unittest
import requests

# 创建测试类
import utils
from api.reg_API import REG_API


class TestLoginAPI(unittest.TestCase):
    #  前置处理
    def setUp(self) -> None:
        # 实例化接口类
        self.loginapi = REG_API()
        # 实例化session
        self.session = requests.session()

    # 后置处理
    def tearDown(self) -> None:
        # 关闭session
        self.session.close()
        # 注册模块

    def test_login(self):
        #  1.获取图片验证码
        response = self.loginapi.get_img(self.session)
        self.assertEqual(200, response.status_code)
        # 2.获取短信验证码
        phone_data = {
            "phone": "18912340067",
            "imgVerifyCode": "8888",
            "type": "reg"
        }
        response = self.loginapi.post_DX(self.session, phone_data)
        print(response.json())
        # self.assertEqual(200, response.status_code)
        # self.assertEqual(200, response.json().get("status"))
        # self.assertIn("短信发送成功", response.text)
        utils.common_assert(self,response,200,200,"短信发送成功")
        # 3.注册
        phone_data = {
            "phone": "18912340067",
            "password": "test123",
            "verifycode": "8888",
            "phone_code": "666666",
            "dy_server": "on"
        }
        response = self.loginapi.post_reg(self.session, phone_data)
        print(response.json())
        # self.assertEqual(200, response.status_code)
        # self.assertEqual(200, response.json().get("status"))
        # self.assertIn("注册成功", response.text)
        utils.common_assert(self,response,200,200,"注册成功")
